<!-- 我的资料 -->
<style lang="less" scoped>
  .r-txt {
    text-align: right;
    width:65%;
  }
  .btn-large {
    border-radius: 0;
  }
  .vux-actionsheet{
    line-height: 30px;
  }

</style>


<template>
  <div class="contain">
    <ul class="text-list">
      <li class="displayflex">
        <span class="l-txt flex1">姓名</span>
        <input class="r-txt" v-model="name" v-bind:readonly="!edit"/>
      </li>
      <li class="displayflex">
        <span class="l-txt flex1">性别</span>
        <input class="r-txt" v-bind:value="Sex?Sex == '1'?'男':'女':''" v-bind:readonly="!edit" @click="selectSex()"/>
        <actionsheet v-model="showSex" :menus="SexMenu" @on-click-menu="SetSex" v-bind:show-cancel="false"></actionsheet>
      </li>
      <li class="displayflex">
        <span class="l-txt flex1">手机号</span>
        <input class="r-txt" v-model="numbers" v-bind:readonly="!edit"/>
      </li>
      <li class="displayflex">
        <span class="l-txt flex1">所属公司</span>
        <input class="r-txt" v-model="DeptName" v-bind:readonly="!edit"/>
      </li>
    </ul>
    <!-- <div class="form-btn">
      <div @click="edit=true" v-if="!edit">编辑资料</div>
      <div class="btn-large" @click="SaveData()" v-if="edit">保存</div>
    </div> -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      name:'',
      Sex:'',
      LogonUser:'',
      numbers:'',
      DeptName:'',
      WareHouseName:'',
      edit:false,
      showSex: false,
      SexMenu:{
        '1': '男',
        '2': '女',
      }
    }
  },
  created(){
    document.title = '我的资料';
    this.getData();
  },
  computed:{
    userinfo(){
      return localStorage.getItem('userinfo') === null?null:JSON.parse(localStorage.getItem('userinfo'));
    }
  },
  methods: {
    getData() {
      if(localStorage.userinfo){
        var userinfo = JSON.parse(localStorage.userinfo); 
        this.name = userinfo.Name;
        this.numbers = userinfo.MobileNo || userinfo.MobileTel1 || userinfo.MobileTel2;
        this.LogonUser = userinfo.LogonUser;
        this.DeptName = userinfo.BelongName;
        this.WareHouseName = userinfo.WareHouseName;
        this.Sex = userinfo.Sex;
      }
    },
    selectSex(){
      if(this.edit){
        this.showSex = true;
      }
    },
    SetSex(e){
      this.Sex = e;
    },
    SaveData(){
      let query = {
        StaffID: this.userinfo.StaffID,
        Name: this.name,
        MobileTel1: this.numbers,
        BelongName: this.DeptName,
        Sex: this.Sex,
        TenantGuid: this.userinfo.TenantGuid,
        CorpGuid: this.userinfo.CorpGuid,
        UpdateUserId: this.userinfo.StaffID,
        UpdateUserName: this.name,
      }
      this.Ajax.post('UpdateMfstaff',query).then((resp) => {
        if (resp.IsSuccess) {
          this.MessageBox.alert('修改成功！').then(action => {
            localStorage.removeItem('userinfo');
            localStorage.setItem('userinfo', JSON.stringify(resp.Data));
            this.$router.push({
              path:'/user'
            });
          });
        } else {
          this.Toast({
            message: resp.ErrorMessage || '操作失败，请稍后重试'
          });
        }
      });
    }
  }
}
</script>
